<template>
  <Modal   :width="400" v-model="model">
    <p slot="header" >
      <Icon type="ios-information-circle"></Icon>
      <span>修改密码</span>
    </p>
    <Form :model="ruleForm" :label-width="100" ref="ruleForm" :rules="rules">
      <FormItem label="公司名" prop="company_name">
        <Input v-model="ruleForm.company_name" placeholder="请输入公司名"/>
      </FormItem>
      <FormItem label="地址" prop="address">
        <Input v-model="ruleForm.address" placeholder="请输入地址"/>
      </FormItem>
    </Form>
    <div slot="footer">
      <Button  size="large" type="text"  @click="onCancel">取消</Button>
      <Button type="primary" size="large"   @click="onDone">确认</Button>
    </div>
  </Modal>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      id: '',
      ruleForm: {
        company_name: '',
        address: ''
      },
      rules: {
        company_name: [
          { required: true, message: '请输入公司名', trigger: 'blur' }
        ],
        address: [
          { required: true, message: "请填写地址", trigger: "blur" },
        ]
      },
      loading: false,
      height: '',
      model: false
    }
  },
  methods: {
    open(id) {
      this.model = true
      this.getCompany()
      this.reset()
      this.$refs['ruleForm'].resetFields()
    },
    getCompany() {
      this.$ajaxGet('/company/info').then(res => {
        this.ruleForm = res
      })
    },
    reset() {
      this.ruleForm.company_name = ''
      this.ruleForm.re_password = ''
    },
    onCancel() {
      this.model = false
      this.reset()
      this.$refs['ruleForm'].resetFields()
    },
    onDone() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          let param = {
            company_name: this.ruleForm.company_name,
            address: this.ruleForm.address,
            company_id: this.ruleForm.company_id
          } 
          let url = '/company/change'
          this.$jsonPost(url, param).then(data => {
            this.$Notice.success({
              title: "修改成功"
            })
            this.$emit('complete')
            this.model = false
          }).catch((res) => {
          })
        }
      })
    }
  },
  computed: {
    ...mapGetters([
      'userInfo'
    ])
  }
}
</script>

